home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / pop3.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  4KB  |  138 lines

  1. /*
  2.     This is a simple pop3 client.
  3.     It connects a pop3 server and wait for commands.
  4.     Be sure you know what you are doing, before connect
  5.     to your popmail server and waste your mail.
  6.     Usage: pop3 [HOST] [AUTO/S]
  7.  
  8.     HOST    the hostname with the pop3 service to connect
  9.     AUTO    connect the pop3 service with login and password
  10.             as defined later.
  11. */
  12.  
  13. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  14. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
  15.  
  16. prg="pop3"
  17.  
  18. if ~RMH_ReadArgs("HOST,AUTO/S") then do
  19.     call PrintFault(IoErr(),prg)
  20.     exit
  21. end
  22.  
  23. if parm.1.flag then do
  24.     /* PUT HERE YOUR DEFAULT HOST, LOGIN and PASS TO BE USED WITH AUTO OPTION */
  25.     host="YOR DEF POP3 HOST"
  26.     userName="YOR DEF LOGIN NAME"
  27.     passWord="YOUR DEF LOGIN PASS"
  28. end
  29. else do
  30.     if ~parm.0.flag then do
  31.         call PrintFault(116,"pop3")
  32.         exit
  33.     end
  34.     host=parm.0.value
  35. end
  36. /******************************************************/
  37. sock = OpenConnection("tcp","pop3",host)
  38. if sock<0 then do
  39.     select
  40.         when sock==-3 then
  41.             say "pop3: service pop3 not found"
  42.         when sock==-2 then
  43.             say "pop3: host <" || host || "> not found (" || HostErrorno() || ")"
  44.         when sock==-1 then
  45.             say "pop3: unable to connect pop3 service at <" || host || "> (" || errno() || ")"
  46.     end
  47.     exit
  48. end
  49. /******************************************************/
  50. CRLF = "D"x || "A"x
  51. ENDMULTI = "."
  52. call rec("SINGLE")
  53. if parm.1.flag then do
  54.     call sen("USER" userName)
  55.     call rec("SINGLE")
  56.     call sen("PASS" password)
  57.     call rec("SINGLE")
  58. end
  59. call init
  60. /******************************************************/
  61. do forever
  62.     parse pull com arg1 arg2 .
  63.     com = upper(com)
  64.     if symbol(com)~="LIT" then err=2
  65.     else do
  66.         err=0
  67.         if value(pop3.com.type)~="POP3."COM".TYPE" then do
  68.             if (pop3.com.args>0 & arg1=="") | (pop3.com.args>1 & arg2=="") then
  69.                 err=1
  70.         end
  71.         else err=2
  72.     end
  73.     if err~=0 then
  74.         select
  75.             when err=1 then say com "need" pop3.com.args "arguments"
  76.             when err=2 then say "unknown command" com
  77.         end
  78.     else do
  79.         if com=="QUITND" then exit
  80.         call sen(com arg1 arg2)
  81.         call rec(pop3.com.type)
  82.         say
  83.         if pop3.com.finish==1 then exit
  84.     end
  85. end
  86. exit
  87. /******************************************************/
  88. init:
  89.     pop3.USER.type="SINGLE";pop3.USER.args=1
  90.     pop3.PASS.type="SINGLE";pop3.PASS.args=1
  91.     pop3.STAT.type="SINGLE";pop3.STAT.args=0
  92.     pop3.LIST.type="MULTI"; pop3.LIST.args=0
  93.     pop3.RETR.type="MULTI"; pop3.RETR.args=1
  94.     pop3.NOOP.type="SINGLE";pop3.NOOP.args=0
  95.     pop3.QUIT.type="SINGLE";pop3.QUIT.args=0;pop3.QUIT.finish=1
  96.     pop3.QUITND.type="SINGLE";pop3.QUITND.args=0;pop3.QUITND.finish=1
  97.     pop3.TOP.type= "MULTI"; pop3.TOP.args=2
  98.     pop3.UIDL.type="SINGLE";pop3.UIDL.args=1
  99.     pop3.DELE.type= "SINGLE";pop3.DELE.args=1
  100.     pop3.RSET.type="SINGLE";pop3.RSET.args=0
  101.     return
  102. /******************************************************/
  103. sen:
  104. parse arg string
  105.     string = string || CRLF
  106.     res = send(sock,string)
  107.     if res~=length(string) then do
  108.         say "pop3: send error (" || errno() || ")"
  109.         exit
  110.     end
  111.     return
  112. /******************************************************/
  113. rec:
  114. parse arg comType
  115.     first=1
  116.     do forever
  117.         len = recvline(sock,"BUF",256)
  118.         if len<0 then do
  119.             say "pop3: recv error (" || errno() || ")"
  120.             exit
  121.         end
  122.         parse var buf buf "D"x
  123.         if first then do
  124.             if left(buf,1)=="-" then do
  125.                 parse var buf "-ERR " text
  126.                 say "   Error from server" text
  127.                 return
  128.             end
  129.             parse var buf buf "+OK " buf
  130.             first=0
  131.         end
  132.         if comType=="MULTI" then
  133.             if buf=ENDMULTI then return
  134.         say buf
  135.         if comType=="SINGLE" then return
  136.     end
  137. /******************************************************/
  138.